package Models;

public enum POSSaleState {
	OPEN_TAB(0),
	CREDIT_CARD(1),
	CASH_CHECK(2),
	GIFT_CARD(3);
	
	private int state;
	
	POSSaleState(final int state){
		this.state = state;
	}
	
	public int getState(){
		return state;
	}
	
	public static POSSaleState getState(final String state){
		return getState(Integer.parseInt(state));
	}
	
	public static POSSaleState getState(final int state){
		switch(state){
		case 0:
			return OPEN_TAB;
		case 1:
			return CREDIT_CARD;
		case 2:
			return CASH_CHECK;
		case 3:
			return GIFT_CARD;
		default:
			throw new EnumConstantNotPresentException(POSSaleState.class, String.valueOf(state));
		}
	}
    
    public static POSSaleState getTypeByName(final String str) {
        if(str.equals("OPEN_TAB")){
            return OPEN_TAB;
        } else if(str.equals("CREDIT_CARD")){
            return CREDIT_CARD;
        } else if(str.equals("CASH_CHECK")){
            return CASH_CHECK;
        } else {
            return GIFT_CARD;
        }
    }
}
